<?php
/**
 * Description of edit
 *
 * @author laimis
 */
class GalleryEdit extends  ActionBase {

    public $title = 'Gallery edit form';
    public $gallery;

    function doEdit(){
        include_once VALIDATEUSER;
        if(true){
            if($this->getGalleryService() != null){
                $gallery = $this->galleryService->getById($_REQUEST['request']['arg']);
                $gallery->title =$_POST['title'];
                $gallery->description =$_POST['description'];
                $gallery->layout_id =$_POST['layout_id'];
                $this->galleryService->save($gallery);
                $_REQUEST['request']['action'] = 'view';
                new GalleryWrapper();
            }else{
                $_GET['error'] = 'Galerijos atnaujinti nepavyko, klaida sistemine, susisiekite su administacija';
                include_once BASEURL.'web/layout.php';
            }
        }else {
            $_GET['error'] = 'Galerijos atnaujinti nepavyko dėl netinkamos informacijos...';
            include_once BASEURL.'web/layout.php';
        }
    }

    public function getGallery(){
        if($this->getGalleryService() != null){
            $this->gallery = $this->galleryService->getById($_REQUEST['request']['arg']);
        }
    }
    public function GalleryEdit(){
        if($_POST['editGallery'] != null){
            if(!$this->isUserLogedIn()){
                include_once BASEURL.'web/layout.php';
            }else{
                $this->doEdit();
            }
        }else{
            $this->getGallery();
            include_once BASEURL.'web/layout.php';
        }
    }
}
?>
